home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / dkbtrace / pbmplus / source / pbmplus.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-31  |  6.3 KB  |  211 lines

  1. /* pbmplus.h - header file for PBM, PGM, PPM, and PNM
  2. **
  3. ** Copyright (C) 1988, 1989, 1991 by Jef Poskanzer.
  4. **
  5. ** Permission to use, copy, modify, and distribute this software and its
  6. ** documentation for any purpose and without fee is hereby granted, provided
  7. ** that the above copyright notice appear in all copies and that both that
  8. ** copyright notice and this permission notice appear in supporting
  9. ** documentation.  This software is provided "as is" without express or
  10. ** implied warranty.
  11. */
  12.  
  13. #ifndef _PBMPLUS_H_
  14. #define _PBMPLUS_H_
  15.  
  16. /*#include <sys\types.h>*/
  17. #include <ctype.h>
  18. #include <stdio.h>
  19.  
  20. #if defined (USG) || defined (SVR4)
  21. #define SYSV
  22. #endif
  23. #if ! ( defined (BSD) || defined (SYSV) || defined (MSDOS) )
  24. /* CONFIGURE: If your system is >= 4.2BSD, set the BSD option; if you're a
  25. ** System V site, set the SYSV option; and if you're IBM-compatible, set
  26. ** MSDOS.  If your compiler is ANSI C, you're probably better off setting
  27. ** SYSV - all it affects is string handling.
  28. */
  29. /* #define BSD */
  30. #define SYSV
  31. #define MSDOS
  32. #endif
  33.  
  34. /* CONFIGURE: If you want to enable writing "raw" files, set this option.
  35. ** "Raw" files are smaller, and much faster to read and write, but you
  36. ** must have a filesystem that allows all 256 ASCII characters to be read
  37. ** and written.  You will no longer be able to mail P?M files without 
  38. ** using uuencode or the equivalent, or running the files through pnmnoraw.
  39. ** Note that reading "raw" files works whether writing is enabled or not.
  40. */
  41. #define PBMPLUS_RAWBITS
  42.  
  43. /* CONFIGURE: PGM can store gray values as either bytes or shorts.  For most
  44. ** applications, bytes will be big enough, and the memory savings can be
  45. ** substantial.  However, if you need more than 8 bits of grayscale resolution,
  46. ** then define this symbol.
  47. */
  48. /* #define PGM_BIGGRAYS */
  49.  
  50. /* CONFIGURE: Normally, PPM handles a pixel as a struct of three grays.
  51. ** If grays are stored in bytes, that's 24 bits per color pixel; if
  52. ** grays are stored as shorts, that's 48 bits per color pixel.  PPM
  53. ** can also be configured to pack the three grays into a single longword,
  54. ** 10 bits each, 30 bits per pixel.
  55. **
  56. ** If you have configured PGM with the PGM_BIGGRAYS option, AND you don't
  57. ** need more than 10 bits for each color component, AND you care more about
  58. ** memory use than speed, then this option might be a win.  Under these
  59. ** circumstances it will make some of the programs use 1.5 times less space,
  60. ** but all of the programs will run about 1.4 times slower.
  61. **
  62. ** If you are not using PGM_BIGGRAYS, then this option is useless -- it
  63. ** doesn't save any space, but it still slows things down.
  64. */
  65. /* #define PPM_PACKCOLORS */
  66.  
  67. /* CONFIGURE: uncomment this to enable debugging checks. */
  68. /* #define DEBUG */
  69.  
  70. #ifdef SYSV
  71.  
  72. #include <string.h>
  73. #define index strchr
  74. #define rindex strrchr
  75. #define srandom srand
  76. #define random rand
  77. #define bzero(dst,len) memset(dst,0,len)
  78. #define bcopy(src,dst,len) memcpy(dst,src,len)
  79. #define bcmp memcmp
  80. extern void srand();
  81. extern int rand();
  82.  
  83. #else /*SYSV*/
  84.  
  85. #include <strings.h>
  86. extern void srandom();
  87. extern long random();
  88.  
  89. #endif /*SYSV*/
  90.  
  91. extern int atoi();
  92. extern void exit();
  93. extern long time();
  94. extern int write();
  95.  
  96. /* CONFIGURE: On some systems, malloc.h doesn't declare these, so we have
  97. ** to do it.  On other systems, for example HP/UX, it declares them
  98. ** incompatibly.  And some systems, for example Dynix, don't have a
  99. ** malloc.h at all.  A sad situation.  If you have compilation problems
  100. ** that point here, feel free to tweak or remove these declarations.
  101. */
  102. /*#include <malloc.h>
  103. extern char* malloc();
  104. extern char* realloc();
  105. extern char* calloc();*/
  106.  
  107. /* CONFIGURE: Some systems don't have vfprintf(), which we need for the
  108. ** error-reporting routines.  If you compile and get a link error about
  109. ** this routine, uncomment the first define, which gives you a vfprintf
  110. ** that uses the theoretically non-portable but fairly common routine
  111. ** _doprnt().  If you then get a link error about _doprnt, or
  112. ** message-printing doesn't look like it's working, try the second
  113. ** define instead.
  114. */
  115. /* #define NEED_VFPRINTF1 */
  116. /* #define NEED_VFPRINTF2 */
  117.  
  118. /* End of configurable definitions. */
  119.  
  120.  
  121. #undef max
  122. #define max(a,b) ((a) > (b) ? (a) : (b))
  123. #undef min
  124. #define min(a,b) ((a) < (b) ? (a) : (b))
  125. #undef abs
  126. #define abs(a) ((a) >= 0 ? (a) : -(a))
  127. #undef odd
  128. #define odd(n) ((n) & 1)
  129.  
  130.  
  131. /* Definitions to make PBMPLUS work with either ANSI C or C Classic. */
  132.  
  133. #if __STDC__
  134. #define ARGS(alist) alist
  135. #else /*__STDC__*/
  136. #define ARGS(alist) ()
  137. #define const
  138. #endif /*__STDC__*/
  139.  
  140.  
  141. /* Initialization. */
  142.  
  143. void pm_init ARGS(( int* argcP, char* argv[] ));
  144.  
  145.  
  146. /* Variable-sized arrays definitions. */
  147.  
  148. char** pm_allocarray ARGS(( int cols, int rows, int size ));
  149. char* pm_allocrow ARGS(( int cols, int size ));
  150. void pm_freearray ARGS(( char** its, int rows ));
  151. void pm_freerow ARGS(( char* itrow ));
  152.  
  153.  
  154. /* Case-insensitive keyword matcher. */
  155.  
  156. int pm_keymatch ARGS(( char* str, char* keyword, int minchars ));
  157.  
  158.  
  159. /* Log base two hacks. */
  160.  
  161. int pm_maxvaltobits ARGS(( int maxval ));
  162. int pm_bitstomaxval ARGS(( int bits ));
  163.  
  164.  
  165. /* Error handling definitions. */
  166.  
  167. void pm_message ARGS(( char*, ... ));
  168. void pm_error ARGS(( char*, ... ));            /* doesn't return */
  169. void pm_perror ARGS(( char* reason ));            /* doesn't return */
  170. void pm_usage ARGS(( char* usage ));            /* doesn't return */
  171.  
  172.  
  173. /* File open/close that handles "-" as stdin and checks errors. */
  174.  
  175. FILE* pm_openr ARGS(( char* name ));
  176. FILE* pm_openw ARGS(( char* name ));
  177. void pm_close ARGS(( FILE* f ));
  178.  
  179.  
  180. /* Endian I/O. */
  181.  
  182. int pm_readbigshort ARGS(( FILE* in, short* sP ));
  183. int pm_writebigshort ARGS(( FILE* out, short s ));
  184. int pm_readbiglong ARGS(( FILE* in, long* lP ));
  185. int pm_writebiglong ARGS(( FILE* out, long l ));
  186. int pm_readlittleshort ARGS(( FILE* in, short* sP ));
  187. int pm_writelittleshort ARGS(( FILE* out, short s ));
  188. int pm_readlittlelong ARGS(( FILE* in, long* lP ));
  189. int pm_writelittlelong ARGS(( FILE* out, long l ));
  190.  
  191. #ifndef __DLL__
  192.  
  193. /* this is for binary stdout for OS/2 */
  194.  
  195. FILE * new_stdout;
  196.  
  197. void main_continued (int, char * *);
  198.  
  199. void main (int argc, char * * argv) {
  200.     new_stdout = fdopen (fileno (stdout), "wb");
  201. #undef stdout
  202. #define stdout new_stdout
  203.     main_continued (argc, argv);
  204. }
  205.  
  206. #define main main_continued
  207.  
  208. #endif
  209.  
  210. #endif /*_PBMPLUS_H_*/
  211.